//
//  SearchVC.m
//  WYModel
//
//  Created by ios on 2017/3/6.
//  Copyright © 2017年 Wy. All rights reserved.
//

#import "SearchVC.h"
#import "WYSearchBar.h"

@interface SearchVC ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) UITableView *wTableView;
@property(nonatomic,strong) WYSearchBar *titleView;
@property(nonatomic,strong) UISearchBar *searchBar;

@end

@implementation SearchVC


- (void)loadView {
    [super loadView];
    
    [self.navigationController.navigationBar setShadowImage:[UIImage imageFromColor:[UIColor clearColor]]];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.searchBar             = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, kWidth-100, 30)];
    self.searchBar.placeholder = @"搜索其他";
    [self.navigationItem setTitleView:self.searchBar];
    
    [self.view addSubview:self.wTableView];
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self scrollViewDidScroll:self.wTableView];
    [self.wTableView reloadData];
    
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
    
    [self navigationBarGradualChangeWithScrollView:scrollView titleView:self.searchBar offset:kRate(180) color:[UIColor purpleColor]];
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 80;
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellID = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell ==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.backgroundColor = [UIColor purpleColor];
    cell.textLabel.text  = [NSString stringWithFormat:@"%ld",indexPath.row];
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 200)];
    blackView.backgroundColor = [UIColor blackColor];
    
    return blackView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 200;
    
}


-(UITableView *)wTableView{
    if (_wTableView == nil) {
        _wTableView            = [[UITableView alloc] initWithFrame:CGRectMake(0, 0,kWidth , kHeight) style:UITableViewStyleGrouped];
        _wTableView.delegate   = self;
        _wTableView.dataSource = self;
        
    }
    return _wTableView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
